# 作者 :南雨
# 时间 : 2022/3/24 9:01

def list_to_region(words: list):
    region = []
    start = 0
    for word in words:
        end = start + len(word)
        region.append((start, end))
        start = end
    return region


def count(standard_list: list, my_list: list):
    """
     计算P、R、F1
     :param standard_list: 官方的分词结果
     :param my_list: 我自己的分词结果
     :return: P, R, F1
    """
    standard_set_size, my_set_size, union = 0, 0, 0

    standard_set, my_set = set(list_to_region(standard_list)), set(list_to_region(my_list))
    standard_set_size += len(standard_set)
    my_set_size += len(my_set)
    # 取standard_set与my_set集合交集
    union += len(standard_set & my_set)
    # 计算精准率
    precision = union / my_set_size * 100
    # 计算召回率
    recall = union / standard_set_size * 100
    # 计算F1
    f1 = 2 * precision * recall / (precision + recall)
    return precision, recall, f1


if __name__ == '__main__':
    pass
